define(function(){
    //兼容IE
    if (!String.prototype.indexOf)
    {
        String.prototype.indexOf = function(s) {
            for (var i = 0; i < this.length - s.length; i++) {
                if (this.charAt(i) === s.charAt(0) &&
                    this.substring(i, s.length) === s) {
                    return i;
                }
            }
            return -1;
        };
    }

    //去除左右空格
    String.prototype.trim = function (){
        return this.replace(/(^\s*)|(\s*$)/g, "");
    };
    //去除左空格
    String.prototype.ltrim = function (){
        return this.replace(/(^\s*)/g, "");
    };
    //去除右空格
    String.prototype.rtrim = function (){
        return this.replace(/(\s*$)/g, "");
    };
    //是否为空
    String.prototype.isEmpty = function(){
        return this === null || this === undefined || this === '';
    };
    //是否在最小长度
    String.prototype.isMinlen  = function(min){
        return this.length >= min;
    };
    //是否在最大长度
    String.prototype.isMaxlen = function(max){
        return  this.length <= max;
    };
    String.prototype.isMaxlen = function(max){
        return  this.length <= max;
    };
    String.prototype.isNumber = function(){
        return /^([0-9]+)+$/.test(this);
    };
    String.prototype.isAlpha = function(){
        return /^([a-zA-Z]+)+$/.test(this);
    };
    String.prototype.isAlnum = function(){
        return /^([a-zA-Z0-9]+)+$/.test(this);
    };
    //是否在长度范围下
    String.prototype.isBetween = function(min , max){
        return  this.length >= min && this.length <= max;
    };
    //是否允许特殊字符
    String.prototype.isAllowchar = function(){
        return ! /\$|\(|\)|\*|\+|\-|\[|\]|\?|\\|\^|\{|\||\}|\~|\`|\!|\#|\%|\&|^_.*?$|\=|\<|\>|\/|\,|\'|\ |\　|\:/.test(this);
    };
    //是否是中文姓名
    String.prototype.isCnName  = function(){
        return /^([\u4e00-\u9fa5]+)$/.test(this);
    };
    //是否是英文姓名
    String.prototype.isEnName  = function(){
        return /^(([a-z]+\s?)+)$/.test(this);
    };
    //是否包含连续的数字
    String.prototype.isSerialNumber  = function(){
        var a = ['012345','123456','234567','345678','456789','987654','876543','765432','654321','543210'];
        for(var i in a)
        {
            if( this.indexOf(a[i]) >= 0){
                return true;
            }
        }
        return false;
    }
    //是否包含三位相同的数字
    String.prototype.isSameNumber  = function(){
        var a = ['111','222','333','444','555','666','777','888','999','000'];
        for(var i in a)
        {
            if( this.indexOf(a[i]) >= 0){
                return true;
            }
        }
        return false;
    }
    //是否是身份证号码
    String.prototype.isIdcard  = function(){
        if(!/^[1-9]\d{5}(18|19|20)?(\d{2})((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}(\d|x|X)$/.test(this)) return false;
        //校验身份码
        var province = {11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",  45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"};
        if(! province[parseInt(this.substring(0,2))]) return false;

        //校验日期码
        var birDay = this.length == 15 ? '19'+this.substring(6,12) : this.substring(6,14);
        var yyyy = parseInt(birDay.substring(0,4),10);
        var mm   = parseInt(birDay.substring(4,6),10);
        var dd   = parseInt(birDay.substring(6),10);
        var xdata = new Date(yyyy,mm-1,dd);
        if(xdata > new Date()){
            return false;//生日不能大于当前日期
        }else if ( ( xdata.getFullYear() != yyyy ) || ( xdata.getMonth () != mm - 1 ) || ( xdata.getDate() != dd ) ){
            return false;
        }
        //18位身份证校验位检测
        if (this.length == 18) {
            var w = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
            var v = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2];
            var s = 0;
            for (var i = 0; i < this.length - 1; i++) {
                s += this[i] * w[i];
            }
            s = s % 11;
            if (v[s] != this[17])  return false;
        }
        return true;
    };
    String.prototype.isBankno  = function(){
        var len = this.length;
        if(len < 15 || len > 19) return false;
        var sum = 0;
        for (var i = len - 2,j = 0; i >= 0; i--,j++) {
            var k = parseInt(this.charAt(i));
            if( j % 2 === 0) k *= 2;
            sum += Math.floor( k / 10 ) + k % 10;
        }

        sum = Math.ceil( sum / 10 ) * 10 - sum;
        return sum == this.charAt(len-1);
    };
    String.prototype.isMobile  = function(){
        return /^1[3-5,7,8]{1}[0-9]{9}$/.test(this);
    };

    return String;
});
